//
//  WBStatusListModel.swift
//  WeiBo
//
//  Created by 韩菲菲 on 16/8/13.
//  Copyright © 2016年 韩菲菲. All rights reserved.
//

import UIKit

class WBStatusListModel: NSObject {
    
    // MARK: - 模型属性
    /// 创建时间
    var created_at: String?
    /// 微博ID
    var id: Int64 = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?
    // 用户模型
    var user: WBUserModel?
    //转发微博
    var retweeted_status: WBStatusListModel?
    //配图 面向模型开发 我就要创建模型
    var pic_urls: [WBPictureInfo]?
    
    //	转发数
    var reposts_count: Int = 0
    //  评论数
    var comments_count: Int = 0
    //  表态数
    var attitudes_count: Int = 0
    
    //重载构造方法
    init(dict:[String:AnyObject]) {
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
        
    }
    
    //字典转模型 模型嵌套模型
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user"{
            
            guard let dict = value as? [String:AnyObject] else{
            
                return
            
            }
            
            user = WBUserModel(dict: dict)
        
        
        }else if key == "retweeted_status"{
            
            guard let dict = value as? [String:AnyObject] else{
                
                return
                
            }
            
            retweeted_status = WBStatusListModel(dict: dict)
        
        }else if key == "pic_urls"{
            
            guard let result = value as? [[String:AnyObject]] else{
                
                return
                
            }
            //创建临时可变数组
            var arrM: [WBPictureInfo] = [WBPictureInfo]()
            //遍历数组
            for dict in result{
            
                //字典转模型
                let model = WBPictureInfo(dict: dict)
                //添加到可变数组中
                arrM.append(model)
            
            }
            //赋值
            pic_urls = arrM
        
        }else
        {
            super.setValue(value, forKey: key)
        
        }
        
    }
    
    //防止KVC报错
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }

}
